package club.mzywucai.blog.air_portal.service.impl;

import club.mzywucai.blog.air_portal.mapper.FileInfoMapper;
import club.mzywucai.blog.air_portal.pojo.po.FileInfoPo;
import club.mzywucai.blog.air_portal.service.AddFileInfoService;
import club.mzywucai.blog.air_portal.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author mzywucai
 * @Description
 * @date 2019/6/2
 */
@Service
public class AddFileServiceImpl implements AddFileInfoService {

    @Autowired
    FileInfoMapper fileInfoMapper;

    @Override
    public void addFile(FileInfoPo fileInfoPo) {
        // 简单加个密
        String filePass = fileInfoPo.getFilePass();
        if (null == filePass) {
            filePass = "";
        }

        if ("" == filePass.trim()) {
            fileInfoPo.setFilePass(filePass);
        }
        // 不为空则加密。
        if (!"".equals(filePass.trim())) {
            String passMd5 = MD5Util.changePass(filePass);
            fileInfoPo.setFilePass(passMd5);
        }

        fileInfoMapper.addFile(fileInfoPo);
    }
}
